1. Field of the Invention
The present invention relates to a computer which has a calculation instruction, and in particular a computer in which an immediate calculation designated by an immediate calculation instruction can efficiently be performed when the immediate calculation instruction is executed to process a large constant. Moreover, the present invention relates to a method for efficiently performing the immediate calculation by utilizing the computer.
2. Description of Background
In general, an immediate calculation instruction, which is a type of machine instruction stored in a prescribed memory section, is read out to a prescribed register of a computer for performing an immediate calculation (that is, a constant calculation). An immediate operand is stored in the immediate calculation instruction.
In detail, register numbers and an immediate value defined by the immediate operand are respectively contained in bit fields provided in the immediate calculation instruction. The contents of a register specified by the register number are utilized for the immediate calculation. Therefore, when the immediate calculation instruction is executed for the immediate calculation, the immediate value, which is equal to a constant, is utilized with the contents of one register.
In the instruction format of the immediate calculation instruction, the number of bits required to contain the register number or the immediate value is determined as follows.
In cases where the number of registers accessed through software is Nr, the register number can be designated in a field in which the number of bits is equal to log.sub.2 Nr. For example, in a computer with 8 to 16 registers, a field occupying 3 to 4 bits is required for designating the register number. On the other hand, the number of bits occupied by a field for containing all types of immediate values utilized in the computer must be equal to the bit width of the register in which the immediate calculation instruction is stored. The bit width of the register is usually 32 bits.
In a computer in which the instruction length is variable, the field for containing the immediate value can occupy the whole width (32 bits) of the immediate calculation instruction. However, in a practical program, the immediate calculation instruction is frequently utilized for performing a specific immediate calculation in which a small constant is processed. Therefore, because the immediate operand contained in a long bit field is always utilized for all immediate calculations, the bit field in the immediate calculation instruction cannot efficiently be utilized.
To achieve the efficient utilization of the bit field in the immediate calculation instruction and to enhance the performance of the computer, it is effective to remove a part of a bit field which is occasionally utilized and shorten the length of the immediate calculation instruction because the capability for transmitting the immediate calculation instruction from a prescribed memory section to a central processing unit is limited to a prescribed level.
Therefore, a short-form immediate instruction in which the bit width of the field for containing the immediate value is shortened is otherwise prepared separately in many cases for the instruction length variable computer. For example, in the instruction set of the MC6800 series provided by the Motorola corporation, in addition to 32-bit, 16-bit, and 8-bit immediate operand forms, a 3-bit immediate operand form is provided. In cases where the number of bits occupied by the field for containing the immediate value is smaller than the number of bits required for the calculation, the number of bits in the field for the immediate operand is extended to a required bit number to execute the immediate calculation instruction by a sign extender or a zero extender in which a required number of "0"s is merely added to the high-order.
However, because the immediate operand is required for executing almost all of the calculation instructions such as an adding-subtracting calculation instruction, a logical calculation instruction, and a register load instruction, the number of instructions is increased by the preparation of a plurality of calculation instructions and register load instructions. Therefore, it takes a long time to interpret the contents of each instruction.
As mentioned above, in the computer in which the instruction length is variable, there are drawbacks that the bit field arranged to the immediate calculation instruction cannot efficiently be utilized and the number of instructions increases so that the performance of the computerdeteriorates.
To solve the above drawbacks, a computer operated by a so-called RISC method has recently been proposed. In the above computer, the number of immediate calculation instructions is reduced and the length of the instructions is fixed so that calling the instructions and interpreting the contents of the instructions is simplified. As a result, the instructions can be executed at high speed.
In the above computer in which the instruction length is fixed, the length of the general instruction is set at 32 bits, which is equal to the whole length of the instruction read out from a prescribed memory section, or half of 32 bits in many cases. The reason why the length of the general instruction is set at 32 or 16 bits is that many instructions such as the instruction for executing a prescribed calculation by reading out the contents of a plurality of registers can be thoroughly stored in the bit field of 32 bits or 16 bits.
However, in the immediate calculation instruction, many fields such as an operation field for containing an operation code are required. Therefore, the number of bits in the immediate field is limited to less than 32 bits. As a result, a large immediate value cannot be contained in the immediate field in cases where the immediate field is too small to contain the large immediate value. That is, the immediate calculation cannot be performed while utilizing a large immediate value.
Therefore, in the immediate calculation in which an immediate value requiring a larger immediate field than the immediate field is utilized, a constant designated by the immediate values initially calculated, for example, in a register file, and then the immediate calculation is performed by reading out both the calculated constant stored in a register and an immediate operand to be processed in the immediate calculation instruction stored in another register. In short, the calculation is performed after the constant and the immediate operand are read out from a plurality of registers. The above calculation is called "calculation between registers".
In other words, in cases where the number of bits in the immediate field is equal to or more than half of the number of bits occupied by the constant, four types of instructions are required. Specifically, the instructions are a load instruction for transmitting a part of the constant C1 to a working register, a shift instruction for shifting that part of the constant C1 to the high-order in the working register, an immediate logical OR instruction for transmitting another part of the specific constant C2 to the low-order in the working register and generating the constant, and a calculation instruction for performing the calculation after the constant and the operation code are read out from a plurality of registers. Therefore, four instructions are executed in the above calculation, while the immediate calculation can generally be performed with a single instruction.
Moreover, in cases where the number of bits occupied by the immediate field is less than half of the number of bits occupied by the specific constant, the required number of shift instructions and the immediate logical OR instructions must be repeated to generate the constant.
As mentioned above, in the computer in which the instruction length is fixed, there is the drawback that it takes a long time to perform the immediate calculation in which a large constant is utilized. Moreover, there is another drawback in that a working register for storing the calculated constant is required.